#include "SPlotCurveData.h"

////////////////////////////////////////////////////////////////////////////////////////////////////
/// \fn	int SPlotCurveData::count() const
///
/// \brief	Constructor.
///
////////////////////////////////////////////////////////////////////////////////////////////////////
SPlotCurveData::SPlotCurveData():
	d_count(0),
	overbook_(true)
{
}
////////////////////////////////////////////////////////////////////////////////////////////////////
/// \fn	void SPlotCurveData::append(double *x, double *y, int count)
///
/// \brief	Adds  "count" points at the curve data.
///
/// \param x a pointer to the array of x coordinate
/// \param y a pointer to the array of y coordinate 
/// \param count the number of element in the array
///
/// \warning this function do not manage the memory
////////////////////////////////////////////////////////////////////////////////////////////////////
void SPlotCurveData::append(double *x, double *y, int count)
{
	
	int newSize;

	/// if overbook is true, reserve more memory while reallocating memory for the 
	/// AddPoint function (process is accelerated because there is no reallocated each time) but add invisible 
	/// point in the curve and maybe offset the scale.
	if (overbook_){
		 newSize = ( (d_count + count) / 1000 + 10 ) * 1000;
	}else{
		 newSize = (d_count + count) ;
	}

	if ( newSize > size() )
	{
		d_x.resize(newSize);
		d_y.resize(newSize);
	}

	for ( register int i = 0; i < count; i++ )
	{
		d_x[d_count + i] = x[i];
		d_y[d_count + i] = y[i];
	}
	d_count += count;
}

////////////////////////////////////////////////////////////////////////////////////////////////////
/// \fn	void SPlotCurveData::append(double *x, double *y, int count)
///
/// \brief	Adds  "count" points at the curve data.
///
/// \param x the  x coordinate
/// \param y the  y coordinate 
///
////////////////////////////////////////////////////////////////////////////////////////////////////
void SPlotCurveData::append(double x, double y)
{
	append(&x, &y, 1);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
/// \fn	int SPlotCurveData::count() const
///
/// \brief	I do not see a real difference between \c count and \c size
///
////////////////////////////////////////////////////////////////////////////////////////////////////
int SPlotCurveData::count() const
{
	return d_count;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
/// \fn	int SPlotCurveData::size() const
///
/// \brief	Return the size of the data (the number of points).
///
////////////////////////////////////////////////////////////////////////////////////////////////////
int SPlotCurveData::size() const
{
	return d_x.size();
}
////////////////////////////////////////////////////////////////////////////////////////////////////
/// \fn	const double *SPlotCurveData::x() const
///
/// \brief	Return a pointer to the array of x values
///
////////////////////////////////////////////////////////////////////////////////////////////////////
const double *SPlotCurveData::x() const
{
	return d_x.data();
}
////////////////////////////////////////////////////////////////////////////////////////////////////
/// \fn	const double *SPlotCurveData::y() const
///
/// \brief	Return a pointer to the array of x values
///
////////////////////////////////////////////////////////////////////////////////////////////////////
const double *SPlotCurveData::y() const
{
	return d_y.data();
}
////////////////////////////////////////////////////////////////////////////////////////////////////
/// \fn	bool SPlotCurveData::overbook() const
///
/// \brief	return the overbook parameter of the curve  
///
/// \remark true by default
/// 
/// if overbook is true, reserve more memory while reallocating memory for the 
/// AddPoint function (process is accelerated because there is no reallocated each time) but add invisible 
/// point in the curve and maybe offset the scale.
///
/// \sa SPlotCurveData::setOverbook( bool val )
////////////////////////////////////////////////////////////////////////////////////////////////////
Q_INVOKABLE bool SPlotCurveData::overbook() const
{
	return overbook_;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
/// \fn	void SPlotCurveData::setOverbook( bool val)
///
/// \brief	set the overbook parameter of the curve  
///
/// \remark true by default
/// 
/// if overbook is true, reserve more memory while reallocating memory for the 
/// AddPoint function (process is accelerated because there is no reallocated each time) but add invisible 
/// point in the curve and maybe offset the scale.
///
/// \sa SPlotCurveData::overbook()
////////////////////////////////////////////////////////////////////////////////////////////////////
Q_INVOKABLE void SPlotCurveData::setOverbook( bool val )
{
	overbook_ = val;
}
